package com.tungse.study.mini_spring.web;

import com.tungse.study.mini_spring.web.annotation.MyResponseBody;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.Method;

/**
 * @Author : Tungse
 * @Date: 2025/4/12 22:04
 * @Description:
 */
@Data
@NoArgsConstructor
public class WebHandler {
    private Object controller;
    private Method method;
    private ResultType resultType;

    public WebHandler(Object controller, Method method){
        this.controller = controller;
        this.method = method;
        this.resultType = resovleResultType(controller, method);
    }

    private ResultType resovleResultType(Object controller, Method method) {
        if(method.isAnnotationPresent(MyResponseBody.class)) {
            return ResultType.JSON;
        }
        return ResultType.HTML;
    }

    enum ResultType {
        JSON, HTML, LOCAL
    }
}
